package com.ai.tool;

import java.util.*;

public class Test {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        System.out.print("please input number of page: ");
        int total = scanner.nextInt();
        Map<String, String> result = transform(total);
        System.out.println("front: " + result.get("front"));
        System.out.println("back: " + result.get("back"));
    }

    public static Map<String, String> transform(int total) {
        List<Integer> frontArr = new ArrayList<>();
        List<Integer> backArr = new ArrayList<>();
        List<Integer> tempArr = frontArr;

        int count = 0;
        for (int i = 1; i <= total; i++) {
            // 1,2放到frontArr；3,4放到backArr；5,6放到frontArr
            tempArr.add(i);
            count++;
            if (count == 2 && tempArr == frontArr) {
                tempArr = backArr;
                count = 0;
            } else if (count == 2 && tempArr == backArr) {
                tempArr = frontArr;
                count = 0;
            }
        }

        String frontString = merge(frontArr);
        String backString = merge(backArr);

        Map<String, String> resultMap = new HashMap<>();

        resultMap.put("front", frontString);
        resultMap.put("back", backString);

        return resultMap;
    }

    public static String merge(List<Integer> arr) {
        StringBuilder result = new StringBuilder();
        int i = 0;
        while (i < arr.size()) {
            String a = arr.get(i) + "-" + arr.get(i + 1);
            i += 2;
            result.append(a);
            if (i != arr.size()) {
                result.append("、");
            }
        }
        return result.toString();
    }
}
